<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>商品管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/treeview.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			var selectedNodeIds = '';
			var setting = {check:{enable:true,nocheckInherit:true},view:{selectedMulti:false},
					data:{simpleData:{enable:true}},
					callback:{
						beforeClick:function(id, node){
						tree.checkNode(node, !node.checked, true, true);
						return false;
						},
						onCheck: function (event, treeId, treeNode) {
						    //alert(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);					
							selectedNodeIds = '';
							var nodes = tree.getCheckedNodes();
							for(var index in nodes) {
								var node = nodes[index];
								var nodeChildren = node.children;
								if(!nodeChildren || nodeChildren.length == 0){
									selectedNodeIds += ("," + node.id);
								}
							}
							$("#classifyIds").val(selectedNodeIds);
						}
					}
				};
			
			// 用户-菜单
			var zNodes=[
					<c:forEach items="${classifyList}" var="menu">{id:"${menu.id}", pId:"${not empty menu.parent.id?menu.parent.id:0}", name:"${not empty menu.parent.id?menu.name:'属性列表'}"},
		            </c:forEach>];
			// 初始化树结构
			var tree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
			// 不选择父节点
			tree.setting.check.chkboxType = { "Y" : "ps", "N" : "ps" };
 			// 默认选择节点
			var ids = "${product.classifyIds}".split(",");
			for(var i=0; i<ids.length; i++) {
				var node = tree.getNodeByParam("id", ids[i]);
				try{tree.checkNode(node, true, false);}catch(e){}
			} 
			// 默认展开全部节点
			tree.expandAll(true);
			
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/eb/product/">商品列表</a></li>
		<li class="active"><a href="${ctx}/eb/product/form?id=${product.id}">商品<shiro:hasPermission name="eb:product:edit">${not empty product.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="eb:product:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="product" action="${ctx}/eb/product/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">产品名称：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="200" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group"  style="display:none">
			<label class="control-label">促销类型：</label>
			<div class="controls">
				<form:input path="type" htmlEscape="false" maxlength="5" class="input-xlarge "/>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">属性：</label>
			<div class="controls">
				<div id="menuTree" class="ztree" style="margin-left:100px;margin-top:3px;float:left;"></div>
				<form:hidden path="classifyIds" />
			</div>
		</div>
		
		<div class="control-group" style="display:none">
			<label class="control-label">产品或套餐：</label>
			<div class="controls">
				<form:input path="isProduct" htmlEscape="false" maxlength="5" value="1" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">商品描述</label>
			<div class="controls">
				<form:textarea id="remarks" htmlEscape="true" path="remarks" rows="4" maxlength="200" class="input-xxlarge required" />
				<sys:ckeditor replace="remarks" uploadPath="/market/sale" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">商品编码：</label>
			<div class="controls">
				<form:input path="code" htmlEscape="false" maxlength="200" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">关键词：</label>
			<div class="controls">
				<form:input path="keywords" htmlEscape="false" maxlength="500" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否上架：</label>
			<div class="controls">
				<form:input path="status" htmlEscape="false" maxlength="5" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">库存：</label>
			<div class="controls">
				<form:input path="inventory" htmlEscape="false" maxlength="11" class="input-xlarge required digits"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">基础销量：</label>
			<div class="controls">
				<form:input path="basicNum" htmlEscape="false" maxlength="11" class="input-xlarge  digits"/>
			</div>
		</div>
		<div class="control-group"  style="display:none">
			<label class="control-label">定价：</label>
			<div class="controls">
				<form:input path="marketPrice" htmlEscape="false" class="input-xlarge  number"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">展示给用户的定价：</label>
			<div class="controls">
				<form:input path="marketPriceForShow" htmlEscape="false" class="input-xlarge  number"/>
			</div>
		</div>
		<div class="control-group"  style="display:none">
			<label class="control-label">成本价：</label>
			<div class="controls">
				<form:input path="costPrice" htmlEscape="false" class="input-xlarge  number"/>
			</div>
		</div>
		<div class="control-group"  style="display:none">
			<label class="control-label">打折的价格：</label>
			<div class="controls">
				<form:input path="salePrice" htmlEscape="false" class="input-xlarge  number"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">真实销售的价格：</label>
			<div class="controls">
				<form:input path="sellPrice" htmlEscape="false" class="input-xlarge required number"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">商品封面图片：</label>
			<div class="controls">
				<form:hidden id="cover" path="cover" htmlEscape="false" maxlength="500" class="input-xlarge"/>
				<sys:ckfinder input="cover" type="files" uploadPath="/hqhsc" selectMultiple="true"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">商品详情图：</label>
			<div class="controls">
				<form:input path="detailImages" htmlEscape="false" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否在电商页面中展现0=显示1=不显示：</label>
			<div class="controls">
				<form:select path="isShow" class="input-xlarge required">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="eb:product:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>